<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
    <title>${message("shop.order.info")}[#if systemShowPowered] - 766 SMART HOME[/#if]</title>
    <meta name="author" content="BIZ Team"/>
    <meta name="copyright" content="BIZ"/>
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=Edge"/>
    <link href="${base}/resources/shop/css/common.css" rel="stylesheet" type="text/css"/>
    <link href="${base}/resources/shop/css/order.css" rel="stylesheet" type="text/css"/>
    <link href="${base}/resources/shop/css/customer.css" rel="stylesheet" type="text/css"/>
    <style type="text/css">
        div.order .info .editReceiver {
            width: 950px;
            position: absolute;
            z-index: 100;
            border: solid 1px #c1c1c1;
            background-color: #ffffff;
        }
        div.order .info .editReceiver th {
            font-weight: normal;
            text-align: right;
            background-color: #ffffff;
        }
    </style>
</head>
<body>
<div id="dialogOverlay" class="dialogOverlay"></div>
[#include "/shop/include/login_header.ftl" /]
<div class="container order">
    <div class="span24">
        <div class="step step2">
            <ul>
                <li>${message("shop.order.step1")}</li>
                <li class="current">${message("shop.order.step2")}</li>
                <li>${message("shop.order.step3")}</li>
            </ul>
        </div>
        <div class="info">
            <form id="receiverForm" action="save_receiver.jhtml" method="post">
                <div id="receiver" class="receiver clearfix">
                    <div class="title">${message("shop.order.receiver")}</div>
                    <ul>
                    [#list member.receivers as receiver]
                        <li[#if receiver_index == 0][#assign defaultReceiver = receiver /]
                                class="selected"[#elseif receiver_index > 3] class="hidden"[/#if]
                                receiverId="${receiver.id}" id="receiverId${receiver.id}">
                            <div>
                                <strong>${receiver.consignee}</strong> ${message("shop.order.receive")}
                            </div>
                            <div>
                                <span>${receiver.areaName}${receiver.address}</span>
                            </div>
                            <div>
                            ${receiver.phone}
                            </div>
                        </li>
                    [/#list]
                    </ul>
                    <p>
                    [#if member.receivers?size > 4]
                        <a href="javascript:;" id="otherReceiverButton"
                           class="button">${message("shop.order.otherReceiver")}</a>
                    [/#if]
                        <a href="javascript:;" id="newReceiverButton" class="button"[#if member.receivers?size > 4]
                           style="display: none;"[/#if]>${message("shop.order.newReceiver")}</a>
                        <a href="javascript:;" id="editReceiverButton" class="button">修改地址</a>
                    </p>
                </div>


                <table id="newReceiver" class="newReceiver[#if member.receivers?has_content] hidden[/#if]">
                    <tr>
                        <th width="100">
                            <span class="requiredField">*</span>${message("shop.order.consignee")}:
                        </th>
                        <td>
                            <input type="text" id="consignee" name="consignee" class="text" maxlength="200"/>
                        </td>
                    </tr>
                    <tr>
                        <th>
                            <span class="requiredField">*</span>${message("shop.order.area")}:
                        </th>
                        <td>
								<span class="fieldSet">
									<input type="hidden" id="areaId" name="areaId"/>
								</span>
                        </td>
                    </tr>
                    <tr>
                        <th>
                            <span class="requiredField">*</span>${message("shop.order.address")}:
                        </th>
                        <td>
                            <input type="text" id="address" name="address" class="text" maxlength="200"/>
                        </td>
                    </tr>
                    <tr>
                        <th>
                            <span class="requiredField">*</span>${message("shop.order.zipCode")}:
                        </th>
                        <td>
                            <input type="text" id="zipCode" name="zipCode" class="text" maxlength="200"/>
                        </td>
                    </tr>
                    <tr>
                        <th>
                            <span class="requiredField">*</span>${message("shop.order.phone")}:
                        </th>
                        <td>
                            <input type="text" id="phone" name="phone" class="text" maxlength="200"/>
                        </td>
                    </tr>
                    <tr>
                        <th>
                        ${message("shop.order.isDefault")}:
                        </th>
                        <td>
                            <input type="checkbox" name="isDefault" value="true"/>
                            <input type="hidden" name="_isDefault" value="false"/>
                        </td>
                    </tr>
                    <tr>
                        <th>&nbsp;

                        </th>
                        <td>
                            <input type="submit" id="newReceiverSubmit" class="button"
                                   value="${message("shop.order.ok")}"/>
                            <input type="button" id="newReceiverCancelButton" class="button"
                                   value="${message("shop.order.cancel")}"/>
                        </td>
                    </tr>
                </table>


            </form>

            <form id="editReceiverForm" action="save_receiver.jhtml" method="post">
                <table id="editReceiver" class="editReceiver[#if member.receivers?has_content] hidden[/#if]">
                    <input type="hidden" name="id" id="editId"/>
                    <tr>
                        <th width="100">
                            <span class="requiredField">*</span>${message("shop.order.consignee")}:
                        </th>
                        <td>
                            <input type="text" id="editConsignee" name="consignee" class="text" maxlength="200"
                                   value="hhh"/>
                        </td>
                    </tr>
                    <tr>
                        <th>
                            <span class="requiredField">*</span>${message("shop.order.area")}:
                        </th>
                        <td>
								<span class="fieldSet">
									<input type="hidden" id="editAreaId" name="areaId"/>
								</span>
                        </td>
                    </tr>
                    <tr>
                        <th>
                            <span class="requiredField">*</span>${message("shop.order.address")}:
                        </th>
                        <td>
                            <input type="text" id="editAddress" name="address" class="text" maxlength="200"/>
                        </td>
                    </tr>
                    <tr>
                        <th>
                            <span class="requiredField">*</span>${message("shop.order.zipCode")}:
                        </th>
                        <td>
                            <input type="text" id="editZipCode" name="zipCode" class="text" maxlength="200"/>
                        </td>
                    </tr>
                    <tr>
                        <th>
                            <span class="requiredField">*</span>${message("shop.order.phone")}:
                        </th>
                        <td>
                            <input type="text" id="editPhone" name="phone" class="text" maxlength="200"/>
                        </td>
                    </tr>
                    <tr>
                        <th>
                        ${message("shop.order.isDefault")}:
                        </th>
                        <td>
                            <input type="checkbox" name="isDefault" value="true"/>
                            <input type="hidden" name="_isDefault" value="false"/>
                        </td>
                    </tr>
                    <tr>
                        <th>&nbsp;

                        </th>
                        <td>
                            <input type="submit" id="editReceiverSubmit" class="button"
                                   value="${message("shop.order.ok")}"/>
                            <input type="button" id="editReceiverCancelButton" class="button"
                                   value="${message("shop.order.cancel")}"/>
                        </td>
                    </tr>
                </table>
            </form>

            <form id="orderForm" action="create.jhtml" method="post">
                <input type="hidden" id="orderType" name="orderType" value="${orderType}"/>
                <input type="hidden" name="jsonParam" value="${jsonParam}"/>
                <input type="hidden" id="order_isTemperature" name="isTemperature" value="${isTemperature}"/>
                <input type="hidden" id="order_isDissipate" name="isDissipate" value="${isDissipate}"/>
                <input type="hidden" id="order_isPromote" name="isPromote" value="${isPromote}"/>
                <input type="hidden" id="order_isController" name="isController" value="${isController}"/>
                <input type="hidden" name="schemeArea" value="${schemeArea}"/>
                <input type="hidden" name="schemeId" value="${schemeId}"/>
                <input type="hidden" id="receiverId" name="receiverId"[#if defaultReceiver??]
                       value="${defaultReceiver.id}"[/#if]/>
                <input type="hidden" name="cartToken" value="${cartToken}"/>
                <dl id="paymentMethod" class="select">
                    <dt>${message("shop.order.paymentMethod")}</dt>
                [#list paymentMethods as paymentMethod]
                    <dd>
                        <label for="paymentMethod_${paymentMethod.id}">
                            <input type="radio" id="paymentMethod_${paymentMethod.id}" name="paymentMethodId"
                                   value="${paymentMethod.id}"/>
                            <span>
										[#if paymentMethod.icon??]
                                            <em style="border-right: none; background: url(${paymentMethod.icon}) center no-repeat;">&nbsp;</em>
                                        [/#if]
                                <strong>${paymentMethod.name}</strong>
									</span>
                            <span title="${paymentMethod.description}">${abbreviate(paymentMethod.description, 80, "...")}</span>
                        </label>
                    </dd>
                [/#list]
                </dl>
                <dl id="shippingMethod" class="select">
                    <dt>${message("shop.order.shippingMethod")}</dt>
                [#list shippingMethods as shippingMethod]
                    <dd>
                        <label for="shippingMethod_${shippingMethod.id}">
                            <input type="radio" id="shippingMethod_${shippingMethod.id}" name="shippingMethodId"
                                   value="${shippingMethod.id}"/>
                            <span>
										[#if shippingMethod.icon??]
                                            <em style="border-right: none; background: url(${shippingMethod.icon}) center no-repeat;">&nbsp;</em>
                                        [/#if]
                                <strong>${shippingMethod.name}</strong>
									</span>
                            <span title="${shippingMethod.description}">${abbreviate(shippingMethod.description, 80, "...")}</span>
                        </label>
                    </dd>
                [/#list]
                </dl>
                <table>
                    <tr>
                        <th colspan="8">${message("shop.order.shopAreaInfo")}</th>
                    </tr>
                    <tr>
                        <td>${message("shop.order.shopAreaCode")}</td>
                        <td>
                            <select onchange="shopAreaMethod('shopAreaCity',this)">
                                <option value="">--请选择--</option>
                            [#if areas??]
                                [#list areas as item]
                                    <option value="${item.id}">${item.name}</option>
                                [/#list]
                            [/#if]
                            </select>
                        </td>
                        <td>${message("shop.order.shopAreaCity")}</td>
                        <td>
                            <select id="shopAreaCity" onchange="shopAreaMethod('shopAreaDistrict',this)">
                                <option value="">--请选择--</option>
                            </select>
                        </td>
                        <td>${message("shop.order.shopAreaDistrict")}</td>
                        <td>
                            <select id="shopAreaDistrict" onchange="shopInfoMethod('shopInfo',this)">
                                <option value="">--请选择--</option>
                            </select>
                        </td>
                        <td>${message("shop.order.shopInfo")}</td>
                        <td>
                            <select id="shopInfo" name="shopId">
                                <option value="">--请选择--</option>
                            </select>
                        </td>
                    </tr>
                </table>
            [#if order.orderType==2]
                <table>
                    <tr>
                        <th colspan="4">方案信息</th>
                    </tr>
                    <tr>
                        <td>
                            方案名称:
                        </td>
                        <td colspan="3">
                        ${order.schemeName}
                        </td>
                    </tr>
                    <tr>
                        <td>
                            方案总价:
                        </td>
                        <td>
                        ${order.amount?string.currency}
                        </td>
                        <td>
                            方案面积:
                        </td>
                        <td>
                        ${order.schemeArea}㎡
                        </td>
                    </tr>
                </table>
            [/#if]
            [#if setting.isInvoiceEnabled]
                <table>
                    <tr>
                        <th colspan="2">${message("shop.order.invoiceInfo")}</th>
                    </tr>
                    <tr>
                        <td width="100">
                        [#--${message("shop.order.isInvoice")}:--]
                            是否开具发票:
                        </td>
                        <td>
                            <label for="isInvoice">
                                <input type="checkbox" id="isInvoice" class='isInvoice' name="isInvoice" value="true"/>
                                <label for='isInvoice'>是</label>
                                <input type="checkbox" id="isInvoice1" class='isInvoice' name="isInvoice" value="false"
                                       checked="checked"/> <label for='isInvoice1'>否</label>
                            </label>
                        </td>
                    </tr>
                    <tr id="invoiceTitleTr" class="hidden">
                    [#--<td width="100">
                        ${message("shop.order.invoiceTitle")}:
                    </td>
                    <td>
                        <input type="text" id="invoiceTitle" name="invoiceTitle" class="text"[#if defaultReceiver??] value="${defaultReceiver.consignee}"[/#if] maxlength="200" />
                    </td>--]


                        <td width="100">
                            发票类型:
                        </td>
                        <td>
                            <input type="checkbox" name="invoiceType" value="0" id='common-invoice' class='g-invoice'/>
                            <label for='common-invoice'>增值税普通发票</label>
                            <input type="checkbox" name="invoiceType" value="1" id='dedicated-invoice'
                                   class='g-invoice'/> <label for='dedicated-invoice'>增值税专用发票</label>
                        </td>
                    </tr>
                    <tr id='common-message'>
                        <td width="100">
                            发票抬头:
                        </td>
                        <td>
                            <input type="text" id="invoiceTitle" name="invoiceTitle" class="text" value=""
                                   maxlength="200"/>
                        </td>
                    </tr>
                </table>
            [/#if]
            [#if order.orderType==1]
                <table class="product">
                    <tr>
                        <th width="60">${message("shop.order.image")}</th>
                        <th>${message("shop.order.product")}</th>
                        <th>订单类型</th>
                        <th>${message("shop.order.price")}</th>
                        <th>${message("shop.order.quantity")}</th>
                        <th>${message("shop.order.subTotal")}</th>
                    </tr>
                    [#list order.orderItems as orderItem]
                        <tr>
                            <td>
                                <img src="[#if orderItem.product.thumbnail??]${orderItem.product.thumbnail}[#else]${setting.defaultThumbnailProductImage}[/#if]"
                                     alt="${orderItem.product.name}"/>
                            </td>
                            <td>
                                <a href="${base}${orderItem.product.path}" title="${orderItem.product.fullName}"
                                   target="_blank">${abbreviate(orderItem.product.fullName, 50, "...")}</a>
                                [#if orderItem.isGift]
                                    <span class="red">[${message("shop.order.gift")}]</span>
                                [/#if]
                            </td>
                            <td>${message("Project.type."+ orderItem.orderType)}</td>
                            <td>
                                [#if !orderItem.isGift]
                                ${currency(orderItem.price, true)}
                                [#else]
                                    -
                                [/#if]
                            </td>
                            <td>
                            ${orderItem.quantity}
                            </td>
                            <td>
                                [#if !orderItem.isGift]
                                ${currency(orderItem.subtotal, true)}
                                [#else]
                                    -
                                [/#if]
                            </td>
                        </tr>
                    [/#list]
                </table>
            [#else]
                <table class="product">
                    <tr>
                        <th width="60">${message("shop.order.image")}</th>
                        <th>主材名称</th>
                        <th>订单类型</th>
                        <th>品牌</th>
                        <th>规格</th>
                    </tr>
                    [#list order.orderItems as orderItem]
                        <tr class="[#if orderItem.name=="温控" || orderItem.name="面板" ][#if !order.isTemperature]hidden[/#if] [#elseif orderItem.name=="卫浴散热器"][#if !order.isDissipate]hidden[/#if][#elseif orderItem.name=="提升泵"][#if !order.isPromote]hidden[/#if][#elseif orderItem.name="控制器"][#if !order.isController]hidden[/#if][#else][/#if]">
                            <td>
                                <img src="[#if orderItem.schemeImage??]${orderItem.schemeImage}[#else]${setting.defaultThumbnailProductImage}[/#if]"
                                     alt="${orderItem.schemeProductName}"/>
                            </td>
                            <td>
                            ${orderItem.name}
                                [#if orderItem.isGift]
                                    <span class="red">[${message("shop.order.gift")}]</span>
                                [/#if]
                            </td>
                            <td>${message("Project.type."+ orderItem.orderType)}</td>
                            <td>${orderItem.schemeProductBrand}</td>
                            <td>${orderItem.schemeProductSpecificationValue}</td>
                        </tr>
                    [/#list]
                </table>
            [/#if]
                <div class="span12">
                    <dl class="memo">
                        <dt>${message("shop.order.memo")}:</dt>
                        <dd>
                            <input type="text" name="memo" maxlength="200"/>
                        </dd>
                    </dl>
                [#--<dl class="coupon"> 优惠券
                    <dt>${message("shop.order.coupon")}:</dt>
                    <dd>
                        <input type="hidden" id="code" name="code" maxlength="200" />
                        <input type="text" id="couponCode" maxlength="200" />
                        <span id="couponName">&nbsp;</span>
                        <button type="button" id="couponButton">${message("shop.order.codeConfirm")}</button>
                    </dd>
                </dl>--]
                </div>
                <div class="span12 last">
                    <ul class="statistic">
                        <li>
								<span>
									${message("shop.order.freight")}: <em
                                            id="freight">${currency(order.freight, true)}</em>
								</span>
                        [#if setting.isInvoiceEnabled && setting.isTaxPriceEnabled]
                            <span class="hidden">
										${message("shop.order.tax")}: <em id="tax">${currency(order.tax, true)}</em>
									</span>
                        [/#if]
                        [#--<span> 积分
                            ${message("shop.order.point")}: <em>${order.point}</em>
                        </span>--]
                        </li>
                        <li>
								<span[#if order.promotionDiscount == 0] class="hidden"[/#if]>
									${message("shop.order.promotionDiscount")}: <em
                                            id="promotionDiscount">${currency(order.promotionDiscount, true)}</em>
								</span>
                            <span[#if order.couponDiscount == 0] class="hidden"[/#if]>
									${message("shop.order.couponDiscount")}: <em
                                            id="couponDiscount">${currency(order.couponDiscount, true)}</em>
								</span>
                        </li>
                        <li>
								<span>
									${message("shop.order.amountPayable")}: <strong
                                            id="amountPayable">${currency(order.amountPayable, true, true)}</strong>
								</span>
                        </li>
                    [#if member.balance > 0]
                        <li>
                            <input type="checkbox" id="useBalance" name="useBalance" value="true"/>
                            <label for="useBalance">
                            ${message("shop.order.useBalance")} (${message("shop.order.balance")}:
                                <em>${currency(member.balance, true)}</em>)
                            </label>
                        </li>
                    [/#if]
                    </ul>
                </div>
                <div class="span24">
                    <div class="bottom">
                        <a href="${base}/cart/list.jhtml" class="back">${message("shop.order.back")}</a>
                        <a href="javascript:;" id="submit" class="submit">${message("shop.order.submit")}</a>
                    </div>
                </div>
                <input id="paramsToken" type="hidden" value="${token}"/>
            [#--发票信息--]
                <div class="invoice-tanchu">
                    <div>
                        <h3>专用发票信息 <img src="${base}/resources/shop/images/off-c.png" class="off-c"/></h3>
                        <div class="invoice-content">
                            <ul class="invoice-company active">
                                <div>1.填写公司信息</div>
                                <li><span><label>*</label>单位名称: </span><input type="text" name="organizationName"
                                                                              class='text'/></li>
                                <li><span><label>*</label>纳税人识别码: </span><input type="text" name="registrationCode"
                                                                                class='text'/></li>
                                <li><span><label>*</label>注册地址: </span><input type="text" name="registerAddress"
                                                                              class='text'/></li>
                                <li><span><label>*</label>注册电话: </span><input type="text" name="registerPhone"
                                                                              class='text'/></li>
                                <li><span><label>*</label>开户银行: </span><input type="text" name="bankOfDeposit"
                                                                              class='text'/></li>
                                <li><span><label>*</label>银行账户: </span><input type="text" name="bankAccount"
                                                                              class='text'/></li>
                                <li>
                                    <div class="invoice-btn">
                                        <button class="invoice-nextStep" type="button">下一步</button>
                                        <button class="off-c" type="button">取消</button>
                                    </div>
                                </li>
                            </ul>
                            <ul class="invoice-personage">
                                <div>2.填写个人信息</div>
                                <li><span><label>*</label>收票人姓名: </span><input type="text" class='text'
                                                                               name="consignee"/></li>
                                <li><span><label>*</label>收票人电话: </span><input type="text" class='text' name="phone"/>
                                </li>
                                <li><span><label>*</label>收票人地址: </span><input type="text" class='text' name="address"/>
                                </li>
                                <li>
                                    <div class="invoice-btn">
                                        <button class="saveInvoiceInfo" type="button">保存</button>
                                        <button class="off-c" type="button">取消</button>
                                    </div>
                                </li>
                            </ul>
                        </div>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>
[#include "/shop/include/fastGetCase.ftl" /]
[#include "/shop/include/footer.ftl" /]
<script type="text/javascript" src="${base}/resources/shop/js/jquery.js"></script>
<script type="text/javascript" src="${base}/resources/shop/js/jQuery-jcContact.js"></script>
<script type="text/javascript" src="${base}/resources/shop/js/public.js"></script>
<script type="text/javascript" src="${base}/resources/shop/js/jquery.lSelect.js"></script>
<script type="text/javascript" src="${base}/resources/shop/js/jquery.validate.js"></script>
<script type="text/javascript" src="${base}/resources/shop/js/common.js"></script>
<script type="text/javascript">
    $().ready(function () {

        var $dialogOverlay = $("#dialogOverlay");
        var $receiverForm = $("#receiverForm");

        var $editReceiverForm = $("#editReceiverForm");

        var $receiver = $("#receiver ul");
        var $otherReceiverButton = $("#otherReceiverButton");
        var $newReceiverButton = $("#newReceiverButton");
        var $newReceiver = $("#newReceiver");

        var $editReceiverButton = $("#editReceiverButton");
        var $editReceiver = $("#editReceiver");
        var $newReceiverSubmit = $("#newReceiverSubmit");
        var $newReceiverCancelButton = $("#newReceiverCancelButton");

        var $editReceiverSubmit = $("#editReceiverSubmit");
        var $editReceiverCancelButton = $("#editReceiverCancelButton");

        var $areaId = $("#areaId");
        var $editAreaId = $("#editAreaId");

        var $orderForm = $("#orderForm");
        var $receiverId = $("#receiverId");
        var $paymentMethodId = $("#paymentMethod :radio");
        var $shippingMethodId = $("#shippingMethod :radio");
        var $isInvoice = $("#isInvoice");
        var $invoiceTitleTr = $("#invoiceTitleTr");
        var $invoiceTitle = $("#invoiceTitle");
        var $code = $("#code");
        var $couponCode = $("#couponCode");
        var $couponName = $("#couponName");
        var $couponButton = $("#couponButton");
        var $useBalance = $("#useBalance");
        var $freight = $("#freight");
        var $promotionDiscount = $("#promotionDiscount");
        var $couponDiscount = $("#couponDiscount");
        var $tax = $("#tax");
        var $amountPayable = $("#amountPayable");
        var $submit = $("#submit");
        var shippingMethodIds = {};

    [@compress single_line = true]
        [#list paymentMethods as paymentMethod]
            shippingMethodIds["${paymentMethod.id}"] = [
                [#list paymentMethod.shippingMethods as shippingMethod]
                    "${shippingMethod.id}"[#if shippingMethod_has_next],[/#if]
                [/#list]];
        [/#list]
    [/@compress]

    [#if !member.receivers?has_content]
        $dialogOverlay.show();
    [/#if]

        // 地区选择
        $areaId.lSelect({
            url: "${base}/common/area.jhtml"
        });
        // 地区选择
        $editAreaId.lSelect({
            url: "${base}/common/area.jhtml"
        });

        // 收货地址
        $("#receiver li").live("click", function () {
            var $this = $(this);
            $receiverId.val($this.attr("receiverId"));
            $("#receiver li").removeClass("selected");
            $this.addClass("selected");
        [#if setting.isInvoiceEnabled]
            if ($.trim($invoiceTitle.val()) == "") {
                $invoiceTitle.val($this.find("strong").text());
            }
        [/#if]
        });

        // 其它收货地址
        $otherReceiverButton.click(function () {
            $otherReceiverButton.hide();
            $newReceiverButton.show();
            $("#receiver li").show();
        });

        // 编辑收货地址
        $editReceiverButton.click(function () {
            var id = $receiverId.val();
            var $receiver = {};
            [#list member.receivers as receiver]
                if(${receiver.id} == id){
                    console.log(id);
                    $receiver['consignee'] = '${receiver.consignee}';
                    $receiver['address'] = '${receiver.address}';
                    $receiver['zipCode'] = '${receiver.zipCode}';
                    $receiver['phone'] = '${receiver.phone}';
                    $receiver['isDefault'] = '${receiver.isDefault}';
                    $receiver['id'] = '${receiver.id}';
                    [#--[#break/]--]
                }
            [/#list]
            $("#editConsignee").val($receiver['consignee']);
            $("#editAddress").val($receiver['address']);
            $("#editZipCode").val($receiver['zipCode']);
            $("#editPhone").val($receiver['phone']);
            $("#editIsDefault").val($receiver['isDefault']);
            $("#editId").val($receiver['id']);
            $dialogOverlay.show();
            $editReceiver.show();
        });

        // 编辑收货地址取消
        $editReceiverCancelButton.click(function () {
            if ($receiverId.val() == "") {
                $.message("warn", "${message("shop.order.receiverRequired")}");
                return false;
            }
            $dialogOverlay.hide();
            $editReceiver.hide();
        });

        // 新收货地址
        $newReceiverButton.click(function () {
            $dialogOverlay.show();
            $newReceiver.show();
        });

        // 新收货地址取消
        $newReceiverCancelButton.click(function () {
            if ($receiverId.val() == "") {
                $.message("warn", "${message("shop.order.receiverRequired")}");
                return false;
            }
            $dialogOverlay.hide();
            $newReceiver.hide();
        });

        // 计算
        function calculate() {
            $.ajax({
                url: "calculate.jhtml",
                type: "POST",
                data: $orderForm.serialize(),
                dataType: "json",
                cache: false,
                success: function (data) {
                    if (data.message.type == "success") {
                        $freight.text(currency(data.freight, true));
                        if (data.promotionDiscount > 0) {
                            $promotionDiscount.text(currency(data.promotionDiscount, true));
                            $promotionDiscount.parent().show();
                        } else {
                            $promotionDiscount.parent().hide();
                        }
                        if (data.couponDiscount > 0) {
                            $couponDiscount.text(currency(data.couponDiscount, true));
                            $couponDiscount.parent().show();
                        } else {
                            $couponDiscount.parent().hide();
                        }
                        if (data.tax > 0) {
                            $tax.text(currency(data.tax, true));
                            $tax.parent().show();
                        } else {
                            $tax.parent().hide();
                        }
                        $amountPayable.text(currency(data.amountPayable, true, true));
                    } else {
                        $.message(data.message);
                        setTimeout(function () {
                            location.reload(true);
                        }, 3000);
                    }
                }
            });
        }

        // 支付方式
        $paymentMethodId.click(function () {
            var $this = $(this);
            if ($this.prop("disabled")) {
                return false;
            }
            $this.closest("dd").addClass("selected").siblings().removeClass("selected");
            var paymentMethodId = $this.val();
            $shippingMethodId.each(function () {
                var $this = $(this);
                if ($.inArray($this.val(), shippingMethodIds[paymentMethodId]) >= 0) {
                    $this.prop("disabled", false);
                } else {
                    $this.prop("disabled", true).prop("checked", false).closest("dd").removeClass("selected");
                }
            });
            calculate();
        });

        // 配送方式
        $shippingMethodId.click(function () {
            var $this = $(this);
            if ($this.prop("disabled")) {
                return false;
            }
            $this.closest("dd").addClass("selected").siblings().removeClass("selected");
            calculate();
        });

        // 开据发票
        $isInvoice.click(function () {
            $invoiceTitleTr.show();
            calculate();
        });
        $('#isInvoice1').click(function () {
            $invoiceTitleTr.hide();
            $('#common-message').hide();
            $('input.g-invoice').attr('checked', false);
        });
        $('.isInvoice').on('click', function () {
            $('.isInvoice:checked').attr('checked', false);
            $(this).attr('checked', true);
        });
        $('#invoiceTitleTr input[type="checkbox"]').on('click', function () {
            $('#invoiceTitleTr input[type="checkbox"]:checked').attr('checked', false);
            $(this).attr('checked', true);
            if ($('#common-invoice').attr('checked') == 'checked') {
                $('#common-message').show();
                $('.invoice-tanchu').hide();
            } else if ($('#dedicated-invoice').attr('checked') == 'checked') {
                $('#common-message').hide();
                $('.invoice-tanchu').show();
                $('.invoice-content ul').removeClass('active');
                $('.invoice-content .invoice-company').addClass('active');
            }
        });
        //-下一步
        $('.invoice-nextStep').click(function () {
            $('.invoice-content ul.active').removeClass('active');
            $('.invoice-content .invoice-personage').addClass('active');
        });
        //-关闭
        $('.off-c').click(function () {
            $('.invoice-tanchu').hide();
        });
        //-保存专用发票信息
        $('.saveInvoiceInfo').click(function () {
            $('.invoice-tanchu').hide();
        });

        // 优惠券
        $couponButton.click(function () {
            if ($code.val() == "") {
                if ($.trim($couponCode.val()) == "") {
                    return false;
                }
                $.ajax({
                    url: "coupon_info.jhtml",
                    type: "POST",
                    data: {code: $couponCode.val()},
                    dataType: "json",
                    cache: false,
                    beforeSend: function () {
                        $couponButton.prop("disabled", true);
                    },
                    success: function (data) {
                        if (data.message.type == "success") {
                            $code.val($couponCode.val());
                            $couponCode.hide();
                            $couponName.text(data.couponName).show();
                            $couponButton.text("${message("shop.order.codeCancel")}");
                            calculate();
                        } else {
                            $.message(data.message);
                        }
                    },
                    complete: function () {
                        $couponButton.prop("disabled", false);
                    }
                });
            } else {
                $code.val("");
                $couponCode.show();
                $couponName.hide();
                $couponButton.text("${message("shop.order.codeConfirm")}");
                calculate();
            }
        });

        // 使用余额
        $useBalance.click(function () {
            calculate();
        });
        var orderType = $("#orderType").val();
        // 订单提交
        $submit.click(function () {
            var $checkedPaymentMethodId = $paymentMethodId.filter(":checked");
            var $checkedShippingMethodId = $shippingMethodId.filter(":checked");
            var shopId = $("#shopInfo").val();
            if (!shopId) {
                $.message("warn", "请选择门店！！");
                return false;
            }
            if ($checkedPaymentMethodId.size() == 0) {
                $.message("warn", "${message("shop.order.paymentMethodRequired")}");
                return false;
            }
            if ($checkedShippingMethodId.size() == 0) {
                $.message("warn", "${message("shop.order.shippingMethodRequired")}");
                return false;
            }
            var invoiceType = $("input[name='invoiceType']:checked").val();
            var isInvoice = $isInvoice.prop("checked");
            if (isInvoice) {
                //要开发票
                if (invoiceType == null || invoiceType == "") {
                    $.message("warn", "请选择发票类型！");
                    return false;
                } else {
                    if (invoiceType == 0 && $.trim($invoiceTitle.val()) == "") {
                        $.message("warn", "${message("shop.order.invoiceTileRequired")}");
                        return false;
                    }
                }
            }

            var submitPath = "";
            if (orderType == 2) {
                submitPath = "createScheme.jhtml";
            } else {
                submitPath = "create.jhtml";
            }
            $.ajax({
                url: submitPath,
                type: "POST",
                data: $orderForm.serialize(),
                dataType: "json",
                cache: false,
                beforeSend: function () {
                    $submit.prop("disabled", true);
                },
                success: function (message) {
                    if (message.type == "success") {
                        var token = $("#paramsToken").val();
                        if (orderType == 1) {
                            location.href = "tlpayment.jhtml?sn=" + message.content + "&token=" + token;
                        } else {
                            $.message("success", "您的订单已提交成功，请等待客服与您联系！");
                            setTimeout(function () {
                                location.href = "${base}/member/order/list.jhtml";
                            }, 3000);
                        }
                    } else {
                        $.message(message);
                        setTimeout(function () {
                            location.reload(true);
                        }, 3000);
                    }
                },
                complete: function () {
                    $submit.prop("disabled", false);
                }
            });
        });

        // 编辑地址表单验证
        $editReceiverForm.validate({
            rules: {
                consignee: "required",
                areaId: "required",
                address: "required",
                zipCode: "required",
                phone: "required"
            },
            submitHandler: function (form) {
                $.ajax({
                    url: "${base}/member/order/save_receiver.jhtml",
                    type: "POST",
                    data: $editReceiverForm.serialize(),
                    dataType: "json",
                    cache: false,
                    beforeSend: function () {
                        $editReceiverSubmit.prop("disabled", true);
                    },
                    success: function (data) {
                        if (data.message.type == "success") {
                            $receiverId.val(data.receiver.id);
                            $("#receiver li").removeClass("selected");
                            $("#receiverId"+$receiverId.val()).addClass("selected").html('<div><strong>' + data.receiver.consignee + '<\/strong> ${message("shop.order.receive")}<\/div><div><span>' + data.receiver.areaName + data.receiver.address + '<\/span><\/div><div>' + data.receiver.phone + '<\/div>');
                            $dialogOverlay.hide();
                            $editReceiver.hide();
                        [#if setting.isInvoiceEnabled]
                            if ($.trim($invoiceTitle.val()) == "") {
                                $invoiceTitle.val(data.receiver.consignee);
                            }
                        [/#if]
                        } else {
                            $.message(data.message);
                        }
                    },
                    complete: function () {
                        $editReceiverSubmit.prop("disabled", false);
                    }
                });
            }
        });
        // 新增地址表单验证
        $receiverForm.validate({
            rules: {
                consignee: "required",
                areaId: "required",
                address: "required",
                zipCode: "required",
                phone: "required"
            },
            submitHandler: function (form) {
                $.ajax({
                    url: "${base}/member/order/save_receiver.jhtml",
                    type: "POST",
                    data: $receiverForm.serialize(),
                    dataType: "json",
                    cache: false,
                    beforeSend: function () {
                        $newReceiverSubmit.prop("disabled", true);
                    },
                    success: function (data) {
                        if (data.message.type == "success") {
                            $receiverId.val(data.receiver.id);
                            $("#receiver li").removeClass("selected");
                            $receiver.append('<li class="selected" receiverId="' + data.receiver.id + '"><div><strong>' + data.receiver.consignee + '<\/strong> ${message("shop.order.receive")}<\/div><div><span>' + data.receiver.areaName + data.receiver.address + '<\/span><\/div><div>' + data.receiver.phone + '<\/div><\/li>');
                            $dialogOverlay.hide();
                            $newReceiver.hide();
                        [#if setting.isInvoiceEnabled]
                            if ($.trim($invoiceTitle.val()) == "") {
                                $invoiceTitle.val(data.receiver.consignee);
                            }
                        [/#if]
                        } else {
                            $.message(data.message);
                        }
                    },
                    complete: function () {
                        $newReceiverSubmit.prop("disabled", false);
                    }
                });
            }
        });

    });
    //三级联查
    function shopAreaMethod(obj, the) {
        var params = $(the).val();
        var str = "<option value=''>--请选择--</option>";
        if (params) {
            $.get("${base}/member/order/searchArea.jhtml", {id: params}, function (data) {
                if (data) {
                    $(data).each(function () {
                        str += "<option value=" + this.id + ">" + this.name + "</option>";
                    });
                    if (data.length > 0) {
                        $("#" + obj).html(str);
                        disabledElement(obj, false);
                        if (obj == "shopAreaCity") {
                            $("#shopAreaDistrict").html(str);
                            $("#shopInfo").html(str);
                            disabledElement("shopAreaDistrict", true);
                            disabledElement("shopInfo", true);
                        } else if (obj == "shopAreaDistrict") {
                            $("#shopInfo").html(str);
                            disabledElement("shopInfo", true);
                        }
                    } else {
                        shopInfoMethod("shopInfo", null, params);
                        disabledElement("shopInfo", false);
                    }
                }
            }, "json");
        } else {
            disabledElement(obj, true);
            disabledElement("shopAreaDistrict", true);
            disabledElement("shopInfo", true);
            $("#shopAreaDistrict").html(str);
            $("#shopInfo").html(str);
        }
    }
    function disabledElement(obj, bool) {
        $("#" + obj).attr("disabled", bool);
    }
    function shopInfoMethod(obj, params, id) {
        var shopId;
        if (null == params) {
            shopId = id;
        } else {
            shopId = $(params).val();
        }
        $.get("${base}/member/order/searchShop.jhtml", {id: shopId}, function (data) {
            if (data) {
                var str = "<option value=''>--请选择--</option>";
                $(data).each(function () {
                    str += "<option value=" + this.id + ">" + this.shopsName + "</option>";
                });
                if (data.length > 0) {
                    disabledElement("shopInfo", false);
                } else {
                    disabledElement("shopInfo", true);
                }
                $("#" + obj).html(str);
            }
        }, "json");
    }
</script>
</body>
</html>